
*=============================================================================

*** Setup

version 15
capture log close
set more off
clear all

* Load data
use "$data/01 Raw Data/02 UK/STAN0125_UK_output.dta" 

*=============================================================================

*** Time Path Question

* Cost treatment indicator

gen coststreaty=CCD_treatment
label define costs 1 "£15" 3 "£60"
lab values coststreaty costs
gen D_coststreaty=.
replace D_coststreaty=0 if coststreaty==1
replace D_coststreaty=1 if coststreaty==3
label var D_coststreaty "Costs High (£60)"

* Outcome

/* 
1 Costs remain the same over the entire period
2 Costs are lower initially and higher later
3 Costs are higher initially and lower later
4 Costs are lower initially, higher in the middle, and lower later
*/

gen cpath=.
replace cpath=1 if Q4_4==1
replace cpath=2 if Q4_4==2
replace cpath=3 if Q4_4==3
replace cpath=4 if Q4_4==4
lab var cpath "Dynamic Climate Cost Preferences"
lab define cpath_lab 1 "Constant" 2 "Increasing" 3 "Decreasing" 4 "Inverse U"
lab values cpath cpath_lab
tab cpath

* Recode so that increasing is the baseline
recode cpath (2=1) (1=2) (3=3) (4=4), gen(cpath_inc)
tab cpath_inc
label define cpath_inc_lab 1 "Increasing" 2 "Constant" 3 "Decreasing" 4 "Inverse U" 
label values cpath_inc cpath_inc_lab

* Generate indicators
tab cpath_inc, gen(pref_)
rename pref_1 pref_inc
rename pref_2 pref_const
rename pref_3 pref_dec
rename pref_4 pref_invu

*=============================================================================

*** Ideology (3 groups)

gen lrideo=LRSP_11
lab var lrideo "Left (1)-Right (10) Ideology"

gen ideo_left=.
replace ideo_left=1 if lrideo<6
replace ideo_left=0 if lrideo>=6 & lrideo!=.

gen ideo_middle=.
replace ideo_middle=1 if lrideo==6
replace ideo_middle=0 if lrideo!=6 & lrideo!=.

gen ideo_right=.
replace ideo_right=1 if lrideo>6 
replace ideo_right=0 if lrideo<=6 & lrideo!=.

*=============================================================================

*** Gender

gen female=.
replace female=0 if DEMO_gender==1
replace female=1 if DEMO_gender==2
lab var female "Female"

*=============================================================================

*** Age

gen age=2018-DEMO_AGE
lab var age "Age"

* Drop if age<18
drop if age<18

* Dummies
gen age1834=(age>=18 & age<=34)
gen age3549=(age>=35 & age<=49)
gen age5064=(age>=50 & age<=64)
gen age65above=(age>=65 & age!=.)

* Categories
gen agegroups=.
lab var agegroups "Age Groups"
replace agegroups=1 if age1834==1
replace agegroups=2 if age3549==1
replace agegroups=3 if age5064==1
replace agegroups=4 if age65above==1

lab define agegroups 1 "18-34" 2 "35-49" 3 "50-64" 4 "65+"
lab values agegroups agegroups

*=============================================================================

*** Income

* Quantile groups
recode DEMO_faminc (1/3=1) (4/5=2) (6/9=3) (10/15=4) (else=.), gen(inc_group)
lab define inc_group_lab 1 "Income: Low" 2 "Income: Lower Middle" 3 "Income: Upper Middle" 4 "Income: High"
label values inc_group inc_group_lab
label var inc_group "Income Groups"
tab inc_group

* Dummies
gen income=DEMO_faminc
replace income=. if DEMO_faminc>13
su income, det

gen inc_bin_high=.
replace inc_bin_high=0 if income<=`r(p50)'
replace inc_bin_high=1 if income>`r(p50)' & income!=.
label var inc_bin_high "Income: Above Median"

gen inc_low=0 if income!=.
replace inc_low=1 if income>1 & income<=4 & income!=.

gen inc_med=0 if income!=.
replace inc_med=1 if income>4 & income<=7  & income!=.

gen inc_high=0 if income!=.
replace inc_high=1 if income>7 & income!=.

*=============================================================================

*** Employment

gen unempl=0
replace unempl=1 if DEMO_employ==3 | DEMO_employ==5

*=============================================================================

*** Education

/*
Years / Code / Label
16 and less	<1> No formal qualifications
16 and less	<2> Youth training certificate/skillseekers
16 and less	<3> Recognised trade apprenticeship completed
16 and less	<4> Clerical and commercial
16 and less	<5> City & Guilds certificate
17-18	<6> City & Guilds certificate - advanced
17-18	<7> ONC
16 and less	<8> CSE grades 2-5
16 and less	<9> CSE grade 1, GCE O level, GCSE, School Certificate
16 and less	<10> Scottish Ordinary/ Lower Certificate
17-18	<11> GCE A level or Higher Certificate
17-18	<12> Scottish Higher Certificate
19+	<13> Nursing qualification (e.g. SEN, SRN, SCM, RGN)
19+	<14> Teaching qualification (not degree)
19+	<15> University diploma
19+	<16> University or CNAA first degree (e.g. BA, B.Sc, B.Ed)
19+	<17> University or CNAA higher degree (e.g. M.Sc, Ph.D)
19+	<18> Other technical, professional or higher qualification
*/

* Dummies
g less_than_hs=0
replace less_than_hs=1 if (DEMO_educ<=5 | DEMO_educ == 8) & DEMO_educ!=.
lab var less_than_hs "Less than HS"

g hs=0
replace hs=1 if (DEMO_educ==6 | DEMO_educ==7 | (DEMO_educ >=9 & DEMO_educ <=12)) & DEMO_educ!=.
lab var hs "HS graduate"

g beyond_hs=0
replace beyond_hs=1 if DEMO_educ>=13 & DEMO_educ<=15 & DEMO_educ!=.
lab var beyond_hs "Beyond HS below BA"

g ba=0
replace ba=1 if DEMO_educ== 16 & DEMO_educ!=.
lab var ba "BA or equivalent"

g beyond_ba=0
replace beyond_ba=1 if DEMO_educ == 17 | DEMO_educ == 18
lab var beyond_ba "Beyond BA"

* Categories
gen school_lowtier=0 if DEMO_educ!=.
replace school_lowtier=1 if less_than_hs == 1 

gen school_medtier=0 if DEMO_educ!=.
replace school_medtier=1 if hs == 1 | beyond_hs == 1

gen school_hightier=0 if DEMO_educ!=.
replace school_hightier=1 if ba == 1 | beyond_ba == 1

* Years of schooling
gen educ_yrs=.
label var educ_yrs "Education Years: 1=16 or less, 2=17-18, 3=19+"
label define educ_yrs_lab 1 "16 or less" 2 "17-18" 3 "19+"
label values educ_yrs educ_yrs_lab

replace educ_yrs=1 if DEMO_educ>=1 & DEMO_educ<=5
replace educ_yrs=1 if DEMO_educ>=8 & DEMO_educ<=10
replace educ_yrs=2 if DEMO_educ>=6 & DEMO_educ<=7
replace educ_yrs=2 if DEMO_educ>=11 & DEMO_educ<=12
replace educ_yrs=3 if DEMO_educ>=13 & DEMO_educ<=18

*=============================================================================

*** Children

gen children=0
replace children=1 if DEMO_children>0

*=============================================================================

*** Saving

compress
save "$data/uk_prep_import.dta", replace
